import BaseUtil from '@/BaseUtil';
import RectUtil from '@/RectUtil';
import SelectUtil from '@/SelectUtil';
import { Rectangle } from '@/rect';
import BooleanCommon from 'code/Core/Common/BooleanCommon';
import SummonCommon from 'code/Core/Common/SummonCommon';
import UnitCommon from 'code/Core/Common/UnitCommon';
import AbilityBase from 'code/Scripts/Abilities/base/AbilityBase';
/**
 * 地狱火
 **/
export default class SS_HelFire extends AbilityBase {
    static instance: SS_HelFire;
    constructor(id: string = 'Adyh') {
        super(id);
        SS_HelFire.instance = this;
        this.init();
        se.onUnitSpellEffect(this.onSpellEffect.bind(this), this.id);
    }
    init() {}
    cast<T extends Object = any>(tarX: number, tarY: number, source: unit, target: unit, data?: T): void {
        BaseUtil.runLater(1, () => {
            let lv = this.getAbilityLevel(source);
            let fp = UnitCommon.getFullProperty(source);
            // UnitCommon.创建召唤物({
            //     id: 'ninf',
            //     x: tarX,
            //     y: tarY,
            //     caster: source,
            //     attr: {
            //         life: fp * lv * 0.7,
            //         attack: 10 * lv + (fp * lv) / 10,
            //         附加护甲: 10 * lv + (fp * lv) / 10,
            //         附加魔抗: 10 * lv + (fp * lv) / 10,
            //     },
            //     lifeTime: 40 + 20 * lv,
            // });
            SummonCommon.summon({
                unitTypeId: 'ninf',
                abilityId: this.id,
                caster: source,
                x: tarX,
                y: tarY,
                lifeTime: 40 + 20 * lv,
                attr: {
                    life: fp * lv * 0.7,
                    attack: 10 * lv + (fp * lv) / 10,
                    附加护甲: 10 * lv + (fp * lv) / 10,
                    附加魔抗: 10 * lv + (fp * lv) / 10,
                },
            });
            let es = SelectUtil.getEnemyUnitsInRange(source, 300, tarX, tarY);
            StunSystemIntance.群体眩晕(es, 2, source);
            let dmg = UnitCommon.取法强(source) * (0.75 + 0.35 * lv) + 80 * lv;
            DamageSystemInstance.applyAoeMagicDamage(es, source, dmg, 'earth', this.id);
            let r: Rectangle = RectUtil.GetRectFromCircle(tarX, tarY, 300);
            r.enumDestructables(null, this.canDestroy);
            r.destroy();
        });
    }
    onSpellEffect() {
        this.cast(GetSpellTargetX(), GetSpellTargetY(), GetTriggerUnit(), GetSpellTargetUnit());
    }
    canDestroy() {
        if (BooleanCommon.isTree(GetEnumDestructable())) KillDestructable(GetEnumDestructable());
    }
}
